package com.zqh.apishoppingcartcud.controller;

import com.zqh.apishoppingcartcud.redis.RedisUtil;
import com.zqh.myfmmall.clients.ShoppingCartCUDClient;
import com.zqh.myfmmall.result.Result;
import com.zqh.myfmmall.rowbeans.entity.ShoppingCart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-03-05 23:00
 */
@RestController
@RequestMapping("shoppingCart/cud")

public class ApiShoppingCartCUDController{
    @Autowired
    private ShoppingCartCUDClient shoppingCartCUDClient;
    @Autowired
    private HttpServletRequest httpServletRequest;
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("create")
    public Result add(@RequestBody ShoppingCart shoppingCart){
        String token = httpServletRequest.getHeader("token");
        String userId = (String) redisUtil.get(token);
        shoppingCart.setUserId(userId);
        return shoppingCartCUDClient.add(shoppingCart);
    }

    /**
     * 功能描述:
     * 购物车接口服务调用，修改购物车信息请求接口
     * @param
     * @return
     * @author kono曾淇杭哒！
     * @date 2022/2/22 22:06
     */
    @PutMapping("update")
    public Result update(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartCUDClient.update(shoppingCart);
    }


    @PutMapping("delete")
    public Result delete(@RequestBody List<String> ids){
        return shoppingCartCUDClient.delete(ids);
    }
}
